﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Text
Imports System.Data
Imports MySql.Data.MySqlClient

Namespace OAMS.DAO
    Public Class BaseDAO

        '''' <summary>
        '''' 取得AUO的資料庫
        '''' </summary>
        '''' <returns></returns>
        '''' <remarks></remarks>
        'Public Function MyConn() As SqlConnection
        '    Dim dbName As String = DBSetting.GetDBName("", "", "")
        '    Dim myConn__1 As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(dbName).ConnectionString)
        '    Return myConn__1
        'End Function
        ''' <summary>
        ''' 取得AUO的資料庫
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function MyConn(ByVal Param1 As String) As SqlConnection
            Dim dbName As String = DBSetting.GetDBName(Param1, "", "")
            Dim myConn__1 As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(dbName).ConnectionString)
            Return myConn__1
        End Function
        Public Function myMYSqlConn(ByVal Param1 As String) As MySql.Data.MySqlClient.MySqlConnection

            Dim mysqlConn1 As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.AppSettings(Param1))


            Return mysqlConn1
        End Function
        Public Function HRConn(ByVal Param1 As String) As SqlConnection
            Dim dbName As String = DBSetting.GetDBName(Param1, "", "")

            Dim myConn__1 As New SqlConnection("Data Source=hrsql1;Initial Catalog=e_offering;User ID=auonewman;Password=auonewman;")
            'Dim myConn__1 As New SqlConnection("Data Source=localhost;Initial Catalog=AUOOAMS;User ID=sa;Password=1234;Connect Timeout=15;Max pool size = 200")
            Return myConn__1
        End Function
        Public Sub ErrorLog(ByVal ProgamName As String, ByVal ErrMsg As String, ByVal FunctionName As String, ByVal byWho As String, ByVal ErrStatus As String, ByVal dbName As String)

            Dim sb As New StringBuilder()
            sb.AppendLine(" insert into  SysErrorLog (Program ,ErrMsg ,FunctionName ,ByWho ,ErrStatus,ErrorDateTime) values(?ProgamName,?ErrMsg,?FunctionName,?byWho,?ErrStatus,?ErrorDateTime) ")
             Dim cmd As MySqlCommand
            Dim con As MySqlConnection = myMYSqlConn(dbName)
            Try
                con.Open()
                cmd = New MySqlCommand(sb.ToString, con)
                If ProgamName.Length > 200 Then
                    cmd.Parameters.AddWithValue("?ProgamName", ProgamName.Substring(0, 200))
                Else
                    cmd.Parameters.AddWithValue("?ProgamName", ProgamName)
                End If
                If ErrMsg.Length > 800 Then

                    cmd.Parameters.AddWithValue("?ErrMsg", ErrMsg.Substring(0, 800))
                Else
                    cmd.Parameters.AddWithValue("?ErrMsg", ErrMsg)

                End If

                If FunctionName.Length > 200 Then
                    cmd.Parameters.AddWithValue("?FunctionName", FunctionName.Substring(0, 200))
                Else
                    cmd.Parameters.AddWithValue("?FunctionName", FunctionName)
                End If

                cmd.Parameters.AddWithValue("?byWho", byWho)
                cmd.Parameters.AddWithValue("?ErrStatus", ErrStatus)
                cmd.Parameters.AddWithValue("?ErrorDateTime", Now)

                cmd.ExecuteNonQuery()
                con.Close()
            Catch ex As Exception
                con.Close()
                ' Throw (New Exception(ex.Message))
            Finally

            End Try


        End Sub
    End Class
End Namespace

